package day5

object Test9_bibao {

  def main(args: Array[String]): Unit = {
    // 目标：掌握闭包
    // 函数引用外部变量（函数返回值得是函数）


    val str: String = m1("升华.png", ".png")
    println(str)

    // result 被称之为闭包
    val result: Int => Int = f1(11)
    println(result(5))

    // 闭包的写法
    var arr = Array("abc.png","zzz","zjd.png","www")
    val gg: String => String = m2("png")
    for (elem <- arr) {
      val gg1 = gg(elem)
      println(gg1)
    }
  }

  def f1 (x:Int) = {
    (y:Int) => y + x
  }

  def m1(fileName:String,suffix:String) = {
    if (fileName.endsWith(suffix)) fileName else suffix
  }



  def m2(suffix:String) = {
    (fileName:String) => if (fileName.endsWith(suffix)) fileName else suffix
  }
}
